using EnvDTE;
using NUnitGenAddIn.Core.Test;

namespace NUnitGenAddIn.VS2005.Test
{
    /// <summary>
    /// Mock File Code Model 2005
    /// </summary>
	public class MockFileCodeModel2005 : MockFileCodeModel
	{
        /// <summary>
        /// Initializes a new instance of the <see cref="MockFileCodeModel2005"/> class.
        /// </summary>
        /// <param name="codeElements">The code elements.</param>
		public MockFileCodeModel2005(MockCodeElements codeElements) : base(codeElements)
		{}

        /// <summary>
        /// Codes the element from point.
        /// </summary>
        /// <param name="point">The point.</param>
        /// <param name="scope">The scope.</param>
        /// <returns><see cref="CodeElement"/> object</returns>
		public override CodeElement CodeElementFromPoint(TextPoint point, vsCMElement scope)
		{
			return codeElementFromPoint(scope, CodeElements);
		}

        /// <summary>
        /// Codes the element from point.
        /// </summary>
        /// <param name="scope">The scope.</param>
        /// <param name="codeElements">The code elements.</param>
        /// <returns><see cref="CodeElement"/> object</returns>
		private static CodeElement codeElementFromPoint(vsCMElement scope, CodeElements codeElements)
		{
			foreach (CodeElement e in codeElements)
			{
			    if (e.Kind == scope)
			    {
			        return e;
			    }
			
                if (e.Children.Count > 0)
                {
                    return codeElementFromPoint(scope, e.Children);
                }
			}
		    return null;
		}
	}
}